<%@page import="com.railway.notice.model.*" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
<html>
<head>
 
	<title><%=NoticeColumns.TABLE_ALIAS%> 维护</title>
    <%@ include file="/commons/listcssjs.jsp" %>
</head>
<body>
<div style="width:1000px;padding:0px;">
<form id="queryForm" name="queryForm" action="${ctx}/notice/Notice/listAjax.do" method="post" style="display: inline;">
	<input type="hidden" id="pageNumber" name="pageNumber" value="1"/>
	<input type="hidden" id="pageSize" name="pageSize" value="20" />
	<div class="queryPanel">

	</div>
	<br></br>
		<div>
			<table id="userDataGrid"></table>
			
		</div>
	</form>
</div>
</body>
<script type="text/javascript">

/**用于回调*/
	 function v_deleteItems(result){
			if (result){
				var rows = $('#userDataGrid').datagrid('getSelections');
				var ids = [];
				if(rows!=null&&rows.length>0){
					$.each(rows,function(i,n){
					   ids.push(n.id)
					});
					$.post( "${ctx}/notice/Notice/delete.do", {"items":ids.join(',')}, 
							function(data){
								$.messager.alert('提示','删除成功','info');
								$('#queryForm').submit();
							}
					);
				}else{
					$.message.alert("请选择后进行删除操作！","warning");
				}
			}
		}
 
		var option = {
				title:'<%=NoticeColumns.TABLE_ALIAS%>',
				iconCls:'icon-save',
				width:1000,
				height:500,
				nowrap: false,
				striped: true,
				pageSize:20,
				collapsible:true,
				url: "${ctx}/notice/Notice/listAjax.do",                                                       
				remoteSort: false,
				idField:
					'id'
																																																												,
				columns:[[
					{field:'ck',checkbox:true}
						
							,{field:'title',title:'<%=NoticeColumns.ALIAS_TITLE%>',width:120,sortable:true}
							
							,{field:'createtimestring',title:'<%=NoticeColumns.ALIAS_CREATE_TIME%>',width:120,sortable:true}
							,{field:'content',title:'<%=NoticeColumns.ALIAS_CONTENT%>',width:120,sortable:true}
							,{field:'imgpath',title:'<%=NoticeColumns.ALIAS_IMGPATH%>',width:120,sortable:true}
							,{field:'creator',title:'<%=NoticeColumns.ALIAS_CREATOR%>',width:120,sortable:true}
							,{field:'expiretimestring1',title:'<%=NoticeColumns.ALIAS_EXPIRE_TIME%>',width:120,sortable:true}
						
						
							 
				]],
				pagination:true,
				rownumbers:true,
				toolbar:[
				{
					id:'btnview',
					text:'查看',
					iconCls:'icon-view',
					handler:function(){
						var selected = $('#userDataGrid').datagrid('getSelected');
						if (selected){
							location.href="${ctx}/notice/Notice/show.do?id="+selected.id;
							return false;
						}
					}
				},'-',{
					id:'btnadd',
					text:'新增',
					iconCls:'icon-create',
					handler:function(){
							location.href="${ctx}/notice/Notice/create.do";
							return false;
					}
				},{
					id:'btnedit',
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						var selected = $('#userDataGrid').datagrid('getSelected');
						if (selected){
							location.href="${ctx}/notice/Notice/edit.do?id="
							+selected.id;
							return false;
						}
					}
				},{
					id:'btndelete',
					text:'删除',
					iconCls:'icon-no',
					handler:function(){
					$.messager.confirm('确认', "确定要删除吗？" ,v_deleteItems);
					}
				}],
				onLoadSuccess: function(){
	            	function bindRowsEvent(){
		                var panel = $('#userDataGrid').datagrid('getPanel');
		                var rows = panel.find('tr[datagrid-row-index]');
		                rows.unbind('click').bind('click',function(e){
		                    return false;
		                });
		                rows.find('div.datagrid-cell-check input[type=checkbox]').unbind().bind('click', function(e){
		                    var index = $(this).parent().parent().parent().attr('datagrid-row-index');
		                    if ($(this).attr('checked')){
		                        $('#userDataGrid').datagrid('selectRow', index);
		                    } else {
		                        $('#userDataGrid').datagrid('unselectRow', index);
		                    }
		                    e.stopPropagation();
		                });
		            }
		            setTimeout(function(){
		                bindRowsEvent();
		            }, 10);    
	    		}
			}


		//重要$(document).ready(handler)
		$(function(){
			//设置form为ajax提交		
			$('#queryForm').form({
				success:function(data){
				data = eval('('+data+')');
				$('#userDataGrid').datagrid("loadData",data);
				}
			});
			//设置datagrid		
			$('#userDataGrid').datagrid(option);
			//设置底部的上一页和下一页
			var p = $('#userDataGrid').datagrid('getPager');
			if (p){
				$(p).pagination({
					onBeforeRefresh:function(){
						//alert('before refresh');
					}
				});
				$(p).pagination({
					onSelectPage:function(pageNumber,pageSize){
						$("input[name='pageNumber']").val(pageNumber);
						$("input[name='pageSize']").val(pageSize);
						$('#queryForm').submit();
					}
				});
			}
			
			}
		); //end $(document).ready(handler)
		//以下这些方法放在这几是为了提供编写javascript参考用，可根据实际情况删除
		function resize(){
			$('#userDataGrid').datagrid('resize', {
				width:1100,
				height:400
			});
		}
		function getSelected(){
			var selected = $('#userDataGrid').datagrid('getSelected');
			if (selected){
				alert(selected.id);
			}
		}
		function getSelections(){
			var ids = [];
			var rows = $('#userDataGrid').datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
				ids.push(rows[i].id);
			}
			alert(ids.join(':'));
		}
		function clearSelections(){
			$('#userDataGrid').datagrid('clearSelections');
		}
		function selectRow(){
			$('#userDataGrid').datagrid('selectRow',1); //行号从0开始
		}
		function selectRecord(){
			$('#userDataGrid').datagrid('selectRecord','1'); //'1'是id值
		}
		function unselectRow(){
			$('#userDataGrid').datagrid('unselectRow',1);//行号从0开始
		}
	</script>
</html>


